# -*- coding: utf-8 -*-
# @Author: Tim Liu
# @Date: 2024-10-22
# @Last Modified by: Tim Liu
# @Last Modified time: 2024-10-22

# @Description: Tool 
# Tools (Actions) enhance the AI's functionality by enabling it to access data from various tool integrations and perform actions. 
# A tool contains name, description, function_name, args_schema_json, tool_type, create_user and config.

from sqlalchemy.orm import relationship, Mapped, mapped_column
from sqlalchemy import String, Integer, ForeignKey, Text
#from datetime import datetime

from db.db_base import BaseModel

from apps.vadmin.auth.models import VadminUser

class ToolDB(BaseModel):
    __tablename__ = "crewplus_tool"
    __table_args__ = ({'comment': 'tools'})

    # Tool name
    name: Mapped[str] = mapped_column(String(255), index=True, nullable=False, comment="Tool Name")
    
    # Tool Description
    description: Mapped[str] = mapped_column(Text, nullable=False, comment="Tool Description. It should be a complete description of the tool, which is used by AI to decide whether and how to use the tool. ")

    # Function name
    function_name: Mapped[str] = mapped_column(String(255), nullable=True, comment="Function Name. It should contain the name of a Python function that implements the tool.")
    
    # function args schema in json  
    args_schema_json: Mapped[str] = mapped_column(Text, nullable=True, comment="Function args schema in json. It should contain a JSON string representing the schema of the tool's arguments. ")
    
    # tool config in json  
    config: Mapped[str] = mapped_column(Text, nullable=True, comment="Function args schema in json. It should contain a JSON string representing the schema of the tool's arguments. ")

    type: Mapped[str] = mapped_column(String(80), nullable=True, comment="Tool Type. It should contain the type of the tool, such as 'platform' for platform tool, 'account', 'custom', etc. ")

    # admin user id of x-api-key
    create_user_id: Mapped[int] = mapped_column(
        Integer,
        ForeignKey("vadmin_auth_user.id", ondelete='RESTRICT'),
        comment="create user id"
    )
    create_user: Mapped[VadminUser] = relationship(foreign_keys=create_user_id)
